import QtQuick
import QtQuick.Controls
import Qt5Compat.GraphicalEffects
import CustomizedComponents

pragma ComponentBehavior: Bound

Item {
    id: root

    width: childrenRect.width
    height: childrenRect.height

    // 文本内容
    property string textSource: "RichStyleText"

    // 文本格式
    property string font: "Helvetica"
    property int fontPixelSize: 50
    property bool bold: true
    property color textColor: "red"
    property var textGradient: Gradient { // 支持渐变颜色文本(竖直方向)
        GradientStop {
            position: 0.0; color: root.textColor
        }
        GradientStop {
            position: 1.0; color: root.textColor
        }
    }
    property bool fontUnderLine: false

    Text {
        id: mask
        text: root.textSource
        font.family: root.font
        font.pixelSize: root.fontPixelSize
        font.bold: root.bold
        font.underline: root.fontUnderLine

        visible: false
    }

    Rectangle {
        anchors.fill: mask
        gradient: root.textGradient
        layer.enabled: true
        layer.effect: OpacityMask {
            maskSource: mask
        }
    }

    GradientMask {
        gradient: root.textGradient
        maskSource: mask
    }
}
